import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.event.*;
import javax.swing.*;
import java.util.ListIterator;
import javax.swing.ImageIcon;
import java.util.Random;

public class Gameboard extends Panel implements MouseListener

{
	BufferedImage image;
	BlankArea[][] spot;
	State gameState;
	boolean humanVSHuman; // this variable if true sets up a human VS human, if
							// false humanVSCom
							// match
	boolean firstPlayer;
	boolean movePeg;
	boolean canplace;
	boolean placed;
	boolean millfound;
	boolean nullmove;
	boolean humanVSAI; // this variable if true sets up a computer VS computer
						// match
	boolean removePeg;
	boolean whiteflying = false;
	boolean blackflying = false;
	int previouspiecex, previouspiecey;
	

	JLabel player = new JLabel("Player  ");
	JLabel action = new JLabel("Action  ");
	GameOption option;

	public Gameboard() {
		JFrame frame = new JFrame("Nine Man's Morris");
		JMenuBar menuBar = new JMenuBar();
		previouspiecex = 888;
		previouspiecey = 888;
		JPanel backgroundpanel = new JPanel();
		JPanel infopanel = new JPanel();

		gameState = new State();

		firstPlayer = true;
		canplace = false;
		placed = false;
		removePeg = false;
		nullmove = false;

		spot = new BlankArea[3][8];
		int boxsize = 25;
		setBounds(0, 0, 500, 500);

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 8; j++) {
				spot[i][j] = new BlankArea();
				spot[i][j].setName(i + " " + j);
				spot[i][j].setBackground(Color.lightGray);
			}
		}

		for (int j = 0; j < 8; j++) {

			for (int i = 0; i < 3; i++) {
				if (j == 0) {
					spot[i][j].setBounds((25) + (54 * i), 20 + (54 * i),
							boxsize, boxsize);

				}
				if (j == 1) {
					spot[i][j]
							.setBounds((205), 20 + (54 * i), boxsize, boxsize);
				}
				if (j == 2) {
					spot[i][j].setBounds((383) - (54 * i), (26) + (54 * i),
							boxsize, boxsize);
				}
				if (j == 3) {
					spot[i][j].setBounds((383) - (54 * i), 205, boxsize,
							boxsize);
				}
				if (j == 4) {
					spot[i][j].setBounds((383) - (54 * i), (388) - (54 * i),
							boxsize, boxsize);
				}
				if (j == 5) {
					spot[i][j].setBounds((205), (388) - (54 * i), boxsize,
							boxsize);
				}
				if (j == 6) {
					spot[i][j].setBounds((25) + (54 * i), (388) - (54 * i),
							boxsize, boxsize);
				}
				if (j == 7) {
					spot[i][j]
							.setBounds((25) + (54 * i), 205, boxsize, boxsize);
				}

			}

		}

		for (int i = 0; i < 3; i++) {
			NeighborPiece temp2 = new NeighborPiece();

			temp2.x = i;
			temp2.y = 0;
			// System.out.println(temp2.y+ " " +temp2.x);

			// gameState.gameboard[i][7].nieghborlist.add(temp2);
			//
			// temp2.x = i;
			// temp2.y = 7;
			// gameState.gameboard[i][0].nieghborlist.add(temp2);

		}

		for (int i = 0; i < 3; i++) {

			for (int j = 0; j < 7; j++) {
				NeighborPiece temp = new NeighborPiece();
				temp.x = i;
				temp.y = j + 1;

				gameState.gameboard[i][j].neighborlist.add(temp);

			}
			for (int j = 1; j < 8; j++) {
				NeighborPiece temp = new NeighborPiece();
				temp.x = i;
				temp.y = j - 1;
				gameState.gameboard[i][j].neighborlist.add(temp);
			}

		}

		for (int i = 0; i < 2; i++) {

			for (int j = 1; j < 8; j = j + 2) {
				NeighborPiece temp = new NeighborPiece();
				temp.x = i + 1;
				temp.y = j;
				gameState.gameboard[i][j].neighborlist.add(temp);
			}
		}

		for (int i = 1; i < 3; i++) {

			for (int j = 1; j < 8; j = j + 2) {
				NeighborPiece temp = new NeighborPiece();
				temp.x = i - 1;
				temp.y = j;
				gameState.gameboard[i][j].neighborlist.add(temp);

			}
		}

		for (int i = 0; i < 3; i++) {

			NeighborPiece temp = new NeighborPiece();
			temp.x = i;
			temp.y = 0;
			gameState.gameboard[i][7].neighborlist.add(temp);
			// figured out the problem, was a pecularality in how java handles
			// objects: note to self, make sure java is supposed to do that
			temp = new NeighborPiece();
			temp.x = i;
			temp.y = 7;
			gameState.gameboard[i][0].neighborlist.add(temp);

		}

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 8; j++) {
				System.out.print("{" + i + "," + j + "} (");

				NeighborPiece temp = new NeighborPiece();
				temp.x = i;
				temp.y = j;
				ListIterator<NeighborPiece> iter = gameState.gameboard[i][j].neighborlist
						.listIterator();
				while (iter.hasNext()) {
					System.out.print(iter.next() + " ");
				}
				System.out.println(")");
			}

		}

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 8; j++) {
				spot[i][j].addMouseListener(this);
				frame.add(spot[i][j]);
			}
		}

		try {
			File input = new File("board.jpg");
			image = ImageIO.read(input);
		} catch (IOException ie) {
			System.out.println("Error:" + ie.getMessage());
		}
		ImageIcon background = new ImageIcon(image);

		JLabel backgroundLabel = new JLabel(background);
		// JLabel whichplayerLabel

		// JLabel picLabel = new JLabel("FUCKING DERP");
		backgroundLabel.setBounds(0, 0, background.getIconWidth(),
				background.getIconHeight());

		backgroundpanel.add(backgroundLabel);
		backgroundpanel.setLayout(null);
		backgroundpanel.setBounds(-10, -10, background.getIconWidth(),
				background.getIconHeight());
		frame.add(backgroundpanel, BorderLayout.CENTER);

		/*
		 * chris adding new labels for player instructions
		 */
		player = new JLabel(
				"Player1 goes first                                           ");
		action = new JLabel("Please place the first peg  ");
		Panel panel = new Panel(new GridLayout(20, 2));
		panel.add(player);
		panel.add(action);
		frame.add(panel, BorderLayout.EAST);

		infopanel.setLayout(null);
		infopanel.setBounds(500, 500, 200, 400);

		JMenu filemenu, optionsmenu, helpmenu;
		JMenuItem savefile, loadfile, restartgame, reset, exit, undo, about;

		filemenu = new JMenu("File");
		optionsmenu = new JMenu("options");
		helpmenu = new JMenu("help");

		menuBar.add(filemenu);

		menuBar.add(optionsmenu);
		menuBar.add(helpmenu);

		// Insets insets = frame.getInsets();

		restartgame = new JMenuItem("New Game");
		savefile = new JMenuItem("Save Game");
		loadfile = new JMenuItem("load Game");
		exit = new JMenuItem("exit");
		reset = new JMenuItem("reset");
		undo = new JMenuItem("undo");
		about = new JMenuItem("about");

		/*
		 * chris i commented out what has not been implemented yet, and what i
		 * dont think we should spend time one finishing
		 */

		// filemenu.add(restartgame);
		// filemenu.add(savefile);
		// filemenu.add(loadfile);
		filemenu.add(reset);
		filemenu.add(exit);
		// optionsmenu.add(undo);
		helpmenu.add(about);

		exit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		reset.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				initalGame();
			}
		});

		about.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				drawTutorial();
			}
		});

		frame.pack();
		frame.setVisible(true);
		frame.getContentPane().setBackground(Color.RED);
		frame.setJMenuBar(menuBar);
		frame.setSize(700, 490); // chris: made a little bigger so we can add
									// New JLabels to the right of the board;
									// start adding at 500
		frame.setVisible(true);
		// frame.setResizable(false);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		option = new GameOption();

		humanVSHuman = option.getHvH();
		humanVSAI = option.getHvC();

	}

	public void paint(Graphics g) {
		g.drawImage(image, 0, 0, null);

	}

	public State getGameState() {
		return gameState;
	}

	private void millCheck(boolean iswhite, GamePiece currentnode, int xcord,
			int ycord) {
		if (boardMillCheck(iswhite, currentnode, xcord, ycord)) {
			removePeg = true;
			action.setText("Please remove a valid peg  ");

		} else {
			//firstPlayer = !firstPlayer;
			//not my code, so I don't know why, but I have to set it to the opposite.  this is probably a terrible place for this code.
			if (!firstPlayer) {
				player.setText("<HTML><FONT COLOR = WHITE>Player1</FONT>, its your turn                              </HTML>");
			} else {
				player.setText("<HTML><FONT COLOR = BLACK>Player2</FONT>, its your turn                              </HTML>");
			}

			if (gameState.white.inhand == 0 && gameState.black.inhand == 0) {
				action.setText("Please move your peg  ");
			} else
				action.setText("Please place your peg on a valid field  ");

			repaint();
		}

	}

	// private boolean boardMillCheck(boolean iswhite, GamePiece currentnode,
	// int xcord, int ycord) {
	//
	// ListIterator<NieghborPiece> currentnodeitr =
	// gameState.gameboard[xcord][ycord].nieghborlist
	// .listIterator();
	// boolean check = false;
	// int milltype = 112;
	// if (iswhite) {
	// milltype = 1;
	// } else {
	// milltype = -1;
	// }
	//
	//
	// //note: change millcheck so adding mill in middle allows you to remove
	// peg.
	// while (currentnodeitr.hasNext()) {
	// NieghborPiece localneighborscord = currentnodeitr.next();
	// if
	// (gameState.gameboard[localneighborscord.x][localneighborscord.y].piecetype
	// == milltype) {
	// ListIterator<NieghborPiece> neighbornodeitr =
	// gameState.gameboard[localneighborscord.x][localneighborscord.y].nieghborlist
	// .listIterator();
	//
	// //loops through the neighbors of the neighbors, if it finds a neighbor
	// with a similar x or y corrident , it checks to see if
	// //it is the same color as the one being checked for mills.
	// while (neighbornodeitr.hasNext()) {
	// NieghborPiece neighborneighborscord = neighbornodeitr.next();
	// //neighbor's neighbor
	//
	//
	// boolean test1 = (neighborneighborscord.x != localneighborscord.x ^
	// neighborneighborscord.y != localneighborscord.y); // makes sure it is not
	// looking at itself
	// boolean test2 = (neighborneighborscord.x == xcord &&
	// neighborneighborscord.y != ycord); // checks for vertical neighbors
	// boolean test3 =
	// (gameState.gameboard[neighborneighborscord.x][neighborneighborscord.y].piecetype
	// == milltype); //checks for a mill itself
	// boolean test4 = (neighborneighborscord.y == ycord &&
	// neighborneighborscord.x != xcord); //checks for horizontal neighbors
	// boolean test5 = (neighborneighborscord.x != xcord ^
	// neighborneighborscord.y != ycord); //makes sure it isn't looking at the
	// piece we started with
	// boolean test6=test5;
	// test5=test6;
	// //note test5 is meaningless, take it out
	//
	// if (test1 && test2 && test3 && test5 ) {
	// check = true;
	// }
	//
	// if (test4 && test3 && test1 && test5 ) {
	// check = true;
	// }
	//
	// }
	//
	// }
	//
	// }
	// return check;
	// }

	private boolean boardMillCheck(boolean iswhite, GamePiece currentnode,
			int xcord, int ycord) {
		int milltype = 112;
		if (iswhite) {
			milltype = 3;
		} else {
			milltype = -3;
		}

		int test1 = 0;
		for (int i = 0; i < 3; i++) {

			test1 = gameState.gameboard[i][0].piecetype
					+ gameState.gameboard[i][1].piecetype
					+ gameState.gameboard[i][2].piecetype;

			if (test1 == milltype) {
				if (containsNode(xcord, ycord, i, 0, 2)) {
					return true;
				}
			}
			test1 = gameState.gameboard[i][2].piecetype
					+ gameState.gameboard[i][3].piecetype
					+ gameState.gameboard[i][4].piecetype;
			if (test1 == milltype) {
				if (containsNode(xcord, ycord, i, 2, 4)) {
					return true;
				}
			}
			test1 = gameState.gameboard[i][4].piecetype
					+ gameState.gameboard[i][5].piecetype
					+ gameState.gameboard[i][6].piecetype;
			if (test1 == milltype) {
				if (containsNode(xcord, ycord, i, 4, 6)) {
					return true;
				}
			}
			test1 = gameState.gameboard[i][6].piecetype
					+ gameState.gameboard[i][7].piecetype
					+ gameState.gameboard[i][0].piecetype;
			// special case as only the first two are in a row, 0 must be
			// checked manually
			if (test1 == milltype) {
				if (containsNode(xcord, ycord, i, 6, 7)) {
					return true;
				}
				if (xcord == i && ycord == 0) {

					return true;
				}
			}
		}
		for (int i = 1; i < 8; i = i + 2) {
			test1 = gameState.gameboard[0][i].piecetype
					+ gameState.gameboard[1][i].piecetype
					+ gameState.gameboard[2][i].piecetype;
			if (test1 == milltype) {
				if (containsNode(xcord, ycord, i)) {
					return true;
				}
			}
		}
		return false;
	}

	// checks to see if node is contained within a set number of y
	private boolean containsNode(int nodeToTestX, int nodeToTestY,
			int xToCheck, int yToStart, int yToEnd) {

		for (int i = yToStart; i <= yToEnd; i++) {
			if (nodeToTestX == xToCheck && nodeToTestY == i) {
				return true;
			}

		}
		return false;
	}

	// checks to see if node is in one of the multilevel mills
	private boolean containsNode(int nodeToTestX, int nodeToTestY, int yToCheck) {

		for (int i = 0; i < 3; i++) {
			if (nodeToTestX == i && nodeToTestY == yToCheck) {
				return true;
			}

		}
		return false;
	}

	private void neighborcheck(int playerid, int xcord, int ycord) {
		removeBlueSquares();
		ListIterator<NeighborPiece> itr = gameState.gameboard[xcord][ycord].neighborlist
				.listIterator();

		while (itr.hasNext()) {
			NeighborPiece temp = itr.next();
			System.out.println("in while " + temp.x + " " + temp.y);

			if (gameState.gameboard[temp.x][temp.y].piecetype == 0) {
				System.out.println(temp.x + " " + temp.y);

				gameState.gameboard[temp.x][temp.y].piecetype = 999;
				spot[temp.x][temp.y].setBackground(Color.BLUE);

			}
		}
		if (whiteflying && firstPlayer) {
			removeBlueSquares();
			for (int j = 0; j < 8; j++) {
				for (int i = 0; i < 3; i++) {
					if (gameState.gameboard[i][j].piecetype == 0) {
						gameState.gameboard[i][j].piecetype = 999;
						spot[i][j].setBackground(Color.BLUE);
					}
				}
			}
			whiteflying = false;
			blackflying = false;
		}

		if (blackflying && !firstPlayer) {
			removeBlueSquares();
			for (int j = 0; j < 8; j++) {
				for (int i = 0; i < 3; i++) {
					if (gameState.gameboard[i][j].piecetype == 0) {
						gameState.gameboard[i][j].piecetype = 999;
						spot[i][j].setBackground(Color.BLUE);
					}
				}
			}
			whiteflying = false;
			blackflying = false;
		}

		System.out.println();

	}

	private void removeBlueSquares() {
		for (int i = 0; i < 3; i++) {

			for (int j = 0; j < 8; j++) {

				if (gameState.gameboard[i][j].piecetype == 999) {
					gameState.gameboard[i][j].piecetype = 0;
					spot[i][j].setBackground(Color.lightGray);
				}

			}

		}

	}

	void eventOutput(String eventDescription, MouseEvent e) {

		String temp = e.getComponent().getName();
		char temp1, temp2;
		int xcord, ycord;
		temp1 = temp.charAt(0);
		temp2 = temp.charAt(2);
		xcord = Character.getNumericValue(temp1);
		ycord = Character.getNumericValue(temp2);

		System.out.println(eventDescription + " " + xcord + " " + ycord + "\n");

		if (firstPlayer) {
			gameState.gameboard[xcord][ycord].piecetype = 1;
			((JComponent) e.getSource()).setBackground(Color.WHITE);
			player.setText("Player1");
			System.out.println("Player1");
		} else {
			gameState.gameboard[xcord][ycord].piecetype = -1;
			((JComponent) e.getSource()).setBackground(Color.BLACK);
			player.setText("Player2");
			System.out.println("Player2");
		}
		repaint();

	}

	public void turn(MouseEvent e) {
//		String temp = e.getComponent().getName();
//		char temp1, temp2;
//		int xcord, ycord; // stands for x cordinate and y cordinate
//		temp1 = temp.charAt(0);
//		temp2 = temp.charAt(2);
//		xcord = Character.getNumericValue(temp1);
//		ycord = Character.getNumericValue(temp2);

		if (humanVSHuman) {
			if (firstPlayer) {
				playerMove(1, e, gameState.white, gameState.black, Color.white);
			} else {
				playerMove(-1, e, gameState.black, gameState.white, Color.black);
			}
			if(removePeg == false && movePeg == false && nullmove ==false){
			firstPlayer = !firstPlayer;
			}
		} else if (humanVSAI) {
				firstPlayer = true;
				playerMove(1, e, gameState.white, gameState.black, Color.white);
				//change this to player has actually moved instead of just movepeg
				if( movePeg == false && removePeg == false  && nullmove == false){
				firstPlayer = false;
				aiMove(-1, e, gameState.black, gameState.white, Color.black);

				}
			

		} else {
			firstPlayer = true;
			aiMove(1, e, gameState.white, gameState.black, Color.white);
			firstPlayer = false;
			aiMove(-1, e, gameState.black, gameState.white, Color.black);

		}

//		if (firstPlayer && !humanVSAI && humanVSHuman) {
//
//		} else if (firstPlayer && humanVSAI) {
//
//		} else if (humanVSHuman) {
//		} else {
//			playerMove(1, e, gameState.white, gameState.black, Color.white);
//			aiMove(-1, e, gameState.black, gameState.white, Color.black);
//		}

	}

	public void playerMove(int playernumber, MouseEvent e,
			PlayerState playerstate, PlayerState otherplayerstate, Color color) {

		String temp = e.getComponent().getName();
		char temp1, temp2;
		int xcord, ycord; // stands for x cordinate and y cordinate
		temp1 = temp.charAt(0);
		temp2 = temp.charAt(2);
		xcord = Character.getNumericValue(temp1);
		ycord = Character.getNumericValue(temp2);

		if (playerstate.inhand > 0
				&& gameState.gameboard[xcord][ycord].piecetype == 0
				&& removePeg == false  ) {
			nullmove = false;
			playerstate.inhand--;
			playerstate.onboard++;

			((JComponent) e.getSource()).setBackground(color);
			gameState.gameboard[xcord][ycord].piecetype = playernumber;
			millCheck(firstPlayer, gameState.gameboard[xcord][ycord], xcord,
					ycord);

		} else if (playerstate.inhand == 0
				&& gameState.gameboard[xcord][ycord].piecetype == playernumber
				&& removePeg == false) {
			previouspiecex = xcord;
			previouspiecey = ycord;
			movePeg = true;
			neighborcheck(playernumber, xcord, ycord);

		} else if (gameState.gameboard[xcord][ycord].piecetype == 999
				&& removePeg == false) {
			movePeg = false;
			nullmove = false;

			((JComponent) e.getSource()).setBackground(color);
			gameState.gameboard[xcord][ycord].piecetype = playernumber;
			spot[previouspiecex][previouspiecey].setBackground(Color.lightGray);
			gameState.gameboard[previouspiecex][previouspiecey].piecetype = 0;
			removeBlueSquares();
			millCheck(firstPlayer, gameState.gameboard[xcord][ycord], xcord,
					ycord);

		} else if (gameState.gameboard[xcord][ycord].piecetype == -(playernumber)
				&& removePeg == true
				&& (boardMillCheck(!firstPlayer,
						gameState.gameboard[xcord][ycord], xcord, ycord) == false) || (removePeg == true && playerstate.onboard < 4)){
			//firstPlayer = !firstPlayer;
			nullmove = false;
			removePeg = false;
			otherplayerstate.onboard--;
			((JComponent) e.getSource()).setBackground(Color.lightGray);
			gameState.gameboard[xcord][ycord].piecetype = 0;

		}
		else{
			nullmove = true;
			
		}

	}

	private void aiMillRemoval() {

		Random generator = new Random();
		int toremovex = generator.nextInt(3);
		int toremovey = generator.nextInt(8);
		boolean legalmove = false;
		int whichplayertoremove = 1020;

		if (firstPlayer == true) {
			whichplayertoremove = -1;

		} else {
			whichplayertoremove = 1;

		}

		while (legalmove == false) {
			if (gameState.gameboard[toremovex][toremovey].piecetype == whichplayertoremove) {
				legalmove = true;
				spot[toremovex][toremovey].setBackground(Color.lightGray);
				gameState.gameboard[toremovex][toremovey].piecetype = 0;
				removeBlueSquares();

			} else {
				toremovex = generator.nextInt(3);
				toremovey = generator.nextInt(8);

			}

		}

	}

	private void aiMove(int playernumber, MouseEvent e,
			PlayerState playerstate, PlayerState otherplayerstate, Color color) {

		Random generator = new Random();
		int aix = generator.nextInt(3);
		int aiy = generator.nextInt(8);
		boolean legalmove = false;

		if (playerstate.inhand > 0) {

			while (legalmove == false) {

				if (gameState.gameboard[aix][aiy].piecetype == 0) {
					playerstate.inhand--;
					playerstate.onboard++;
					legalmove = true;

					spot[aix][aiy].setBackground(color);

					gameState.gameboard[aix][aiy].piecetype = playernumber;
					boolean test1 = boardMillCheck(firstPlayer, gameState.gameboard[aix][aiy], aix, aiy);

					if (test1) {
						aiMillRemoval();
					}
				} else {
					aix = generator.nextInt(3);
					aiy = generator.nextInt(8);

				}

			}

		} else {
			while (legalmove == false) {
				ListIterator<NeighborPiece> itr = gameState.gameboard[aix][aiy].neighborlist
						.listIterator();
				boolean openneighbor = false;
				int neighborx = 0;
				int neighbory = 0;

				while (itr.hasNext() && openneighbor == false) {
					NeighborPiece temp = itr.next();

					if (gameState.gameboard[temp.x][temp.y].piecetype == 0) {
						openneighbor = true;
						neighborx = temp.x;
						neighbory = temp.y;
					}
				}

				if (gameState.gameboard[aix][aiy].piecetype == playernumber
						&& removePeg == false && openneighbor == true) {
					legalmove = true;
					spot[neighborx][neighbory].setBackground(color);
					gameState.gameboard[neighborx][neighbory].piecetype = playernumber;
					spot[aix][aiy].setBackground(Color.lightGray);
					gameState.gameboard[aix][aiy].piecetype = 0;
					removeBlueSquares();

					boolean player = firstPlayer;
					if (boardMillCheck(firstPlayer,
							gameState.gameboard[neighborx][neighborx],
							neighborx, neighborx)) {
						aiMillRemoval();
					}
				} else {
					aix = generator.nextInt(3);
					aiy = generator.nextInt(8);

				}

			}

		}
		//firstPlayer = !firstPlayer;
		boolean player = firstPlayer;
		int der = 2;

	}

	public void mousePressed(MouseEvent e) {

		turn(e);

	}

	public void mouseReleased(MouseEvent e) {
		if (gameState.black.onboard < 3 && gameState.black.inhand == 0) {
			JOptionPane.showMessageDialog(null, "White is the Winner!",
					"CONGRATULATIONS", 1);
		}
		if (gameState.white.onboard < 3 && gameState.white.inhand == 0) {
			JOptionPane.showMessageDialog(null, "Black is the Winner!",
					"CONGRATULATIONS", 1);
		}
		if (gameState.black.onboard == 3 && gameState.black.inhand == 0) {
			blackflying = true;
		}
		if (gameState.white.onboard == 3 && gameState.white.inhand == 0) {
			whiteflying = true;
		}
	}

	public void mouseEntered(MouseEvent e) {
		humanVSHuman = option.getHvH();
		humanVSAI = option.getHvC();
		
	}

	public void mouseExited(MouseEvent e) {
	}

	public void mouseClicked(MouseEvent e) {

	}

	public void initalGame() {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 8; j++) {
				gameState.gameboard[i][j].piecetype = 0;
				spot[i][j].setBackground(Color.lightGray);
			}
		}
		gameState.black.inhand = 9;
		gameState.white.inhand = 9;
		gameState.black.onboard = 0;
		gameState.white.onboard = 0;
		firstPlayer = !firstPlayer;
		canplace = false;
		placed = false;
		removePeg = false;
		nullmove = false;
		this.blackflying = false;
		this.whiteflying = false;
		this.removePeg = false;

	}

	public void drawTutorial() {
		/*
		 * draw tutorial in an JOptionPane
		 */
		String output = "This is your tutorial\n\n"
				+ "\tThe goal of the game is to reduce the opponents 'pegs' to 2. To do this you will have to form 'mills'.\n"
				+ "Mills can be formed by placing 3 pegs of the same color in a row or colum that is connected with a line.\n"
				+ "Once a mill is formed the game will expect you to remove a peg.\n\n"
				+ "\tTo start the game, simply place pegs on empty fields on the board, until no player has any pegs left to \n"
				+ "place. If during this process a player forms a mill, that player can remove one of the opponents pegs and \n"
				+ "the game continues normally. \n\n"
				+ "<html>\tTo move a peg simply click on any peg in your color and the surrounding (empty) boxes will be painted <FONT COLOR = blue>blue</FONT></html>,\n"
				+ "those boxes indicate possible places to move to, from the current location. Once you moved, and have not formed\n"
				+ "a mill your turn is over. If you have formed a mill you have to remove a peg of your opponent.\n\n "
				+ "Once any player has 2 pegs, the other player will be declared the winner.";

		JOptionPane.showMessageDialog(null, output, "TUTORIAL", -1);

	}

	static public void main(String args[]) throws Exception {

		State currentstate = new State();
		Gameboard board = new Gameboard();
		GameData test = new GameData();
		// board.firstPlayerLoop();

	}

}
